package com.hangxin.word.controller;

import com.hangxin.common.core.controller.BaseController;
import com.hangxin.common.core.domain.AjaxResult;
import com.hangxin.common.core.domain.R;
import com.hangxin.common.core.page.TableDataInfo;
import com.hangxin.word.domain.StandardWordInfo;
import com.hangxin.word.service.ISimilarWordInfoService;
import com.hangxin.word.service.IStandardWordInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 语义相近词 Controller
 *
 * @author ZX
 */
@RestController
@RequestMapping("/word/semantics")
public class SemanticallySimilarWordsController extends BaseController {

    @Autowired
    private IStandardWordInfoService standardWordInfoService;
    @Autowired
    private ISimilarWordInfoService similarWordInfoService;

    /**
     * 查询标准词列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StandardWordInfo standardWordInfo) {
        startPage();
        List<StandardWordInfo> standardWordInfos = standardWordInfoService.listWithSimilar(standardWordInfo);
        return getDataTable(standardWordInfos);
    }

    /**
     * 确认同义词
     */
    @PutMapping("/confirm")
    public AjaxResult confirm(@RequestParam List<Long> ids) {
        standardWordInfoService.confirmSimilar(ids);
        return AjaxResult.success();
    }

    /**
     * 删除标准词
     */
    @DeleteMapping("/standard/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(standardWordInfoService.removeStandardAndSimilar(id));
    }

    /**
     * 删除相近词
     */
    @DeleteMapping("/similar/{id}")
    public AjaxResult removeSimilar(@PathVariable Long id) {
        similarWordInfoService.removeById(id);
        return toAjax(1);
    }
}
